package com.dxiang.demo.utils;

import org.dozer.DozerBeanMapper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BeanMapDozer {
	
	 private static DozerBeanMapper mapper = new DozerBeanMapper();
	 
	 static{
		 mapper.setMappingFiles(Collections.singletonList("dozerJdk8Converters.xml"));
	 }
	
	public static <T> T map(Object source, Class<T> destinationClass){
		return mapper.map(source, destinationClass);
	}
	
	public static void setObject(Object source,Object target){  
        mapper.map(source, target);  
    }
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static List getList(List source,Class cls){  
        List listTarget = new ArrayList();  
        if(source != null){  
            for (Object object : source) {  
                Object objTarget = mapper.map(object, cls);  
                listTarget.add(objTarget);  
            }  
        }  
        return listTarget;  
    }
	
}
